package com.fmi.timedealer.notifications;

import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class PlansNotificationManager {

	private static PlansNotificationManager instance = null;
	
	protected PlansNotificationManager() {
	}
	
	public static PlansNotificationManager getInstance() {
		if(instance == null) {
			instance = new PlansNotificationManager();
		}
		return instance;
	}
	
	public void setAutoNotifications(Context context) {

		Calendar updateTime = Calendar.getInstance();
	    updateTime.set(Calendar.MINUTE, 0);
	    updateTime.set(Calendar.SECOND, 0);
	 
	    Intent receiver = new Intent(NotificationReceiver.BROADCAST_ACTION);
	    PendingIntent recurringNotification = PendingIntent.getBroadcast(context,
	            0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
	    
	    AlarmManager alarms = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
	    
	    Toast.makeText(context, updateTime.getTime().toString(), Toast.LENGTH_LONG).show();
	    
	    alarms.setRepeating(AlarmManager.RTC_WAKEUP,
	            updateTime.getTimeInMillis(),
	            AlarmManager.INTERVAL_HOUR, recurringNotification); 
	}
	
	public void setNotification(Context context) {
		Intent receiver = new Intent(NotificationReceiver.BROADCAST_ACTION);
		context.sendBroadcast(receiver);
	}
}
